var net = require('net');
/**
 * 服务端sever
 */

var last_pkg = null;

var server = net.createServer((client_sock)=>{
    console.log('======createServer=======',client_sock.remoteAddress,client_sock.remotePort);

  
    client_sock.on('close',function(e){
        console.log('======client_sock err===========',e);
    })

 
    client_sock.on("data", function(data) {
        console.log('=======client_sock=data========',data);

        const stringValue = data.toString('utf8', 0, data.length);
        console.log('=== client_sock=stringValue======',stringValue)

        client_sock.write("goodbye!!!");

        client_sock.read(data);

        client_sock.end(); // 正常关闭
    });

    client_sock.on('error',function(err){
        console.log('err',err);
    })
})

server.on('connection',function(){
    console.log('======server=connection========');
});

server.on('listening',function(){
    console.log("start listening...");
});

server.on('close',function(){
    console.log('=====server=close===========');
});

server.on('error',function(err){
    console.log('=====server=error===========',err);
});

server.listen({
	port: 6080,
	host: "127.0.0.1",
	exclusive: true,
});
